/* ==========================================================================
   变量定义
   ========================================================================== */
:root {
    /* 主题色变量 */
    --primary-color: #4CAF50;
    --primary-dark: #45a049;
    --primary-light: #81C784;
    
    /* 文本颜色 */
    --text-color: #2c3e50;
    --text-color-light: #ffffff;
    
    /* 背景颜色 */
    --bg-color: #f8f9fa;
    --bg-color-dark: #1a1a1a;
    --bg-color-darker: #121212;
    
    /* 其他颜色 */
    --weekend-color: #FF5722;
    --border-color: #eee;
    --border-color-dark: #333;
    --focus-color: #2196F3;
    --focus-outline: 3px solid var(--focus-color);
    
    /* 尺寸变量 */
    --border-radius-sm: 6px;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --border-radius-xl: 16px;
    
    /* 阴影变量 */
    --shadow-sm: 0 4px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.1);
    --shadow-dark: 0 4px 8px rgba(0, 0, 0, 0.3);
    
    /* 动画变量 */
    --transition-base: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --animation-duration: 0.3s;
    --ripple-duration: 0.6s;
}

/* 深色模式变量 */
[data-theme="dark"] {
    --primary-color: #66BB6A;
    --primary-dark: #43A047;
    --primary-light: #81C784;
    
    --text-color: #ffffff;
    --text-color-light: #ffffff;
    
    --bg-color: #1a1a1a;
    --bg-color-dark: #121212;
    --bg-color-darker: #000000;
    
    --border-color: #333;
    --border-color-dark: #444;
    
    --shadow-sm: 0 4px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 15px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* 主题色变量 */
[data-theme-color="blue"] {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #64B5F6;
}

[data-theme-color="purple"] {
    --primary-color: #9C27B0;
    --primary-dark: #7B1FA2;
    --primary-light: #BA68C8;
}

[data-theme-color="orange"] {
    --primary-color: #FF9800;
    --primary-dark: #F57C00;
    --primary-light: #FFB74D;
}

/* ==========================================================================
   可访问性基础样式
   ========================================================================== */
/* 跳过导航链接 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    z-index: 100;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* 焦点样式 */
:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 2px;
}

/* 高对比度模式 */
@media (forced-colors: active) {
    .calendar-day.selected {
        border: 2px solid CanvasText;
    }
    
    button {
        border: 2px solid CanvasText;
    }
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================================================
   基础样式
   ========================================================================== */
body {
    font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.container {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: var(--border-radius-xl);
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 800px;
    width: 95%;
    backdrop-filter: blur(10px);
    animation: fadeIn 0.8s ease-out;
    will-change: transform, opacity;
    transform: translateZ(0);
}

/* ==========================================================================
   日历组件
   ========================================================================== */
/* 日历容器 */
.calendar {
    margin: 20px 0;
    border: none;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    background: white;
    box-shadow: var(--shadow-sm);
    animation: scaleIn 0.6s ease-out;
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style paint;
}

/* 日历头部 */
.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: linear-gradient(to right, var(--primary-color), var(--primary-dark));
    color: white;
    will-change: transform;
    transform: translateZ(0);
}

/* 日历头部控件 */
.calendar-header select,
.calendar-header button {
    padding: 8px 15px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 15px;
    margin: 0 5px;
    cursor: pointer;
    transition: var(--transition-base);
}

.calendar-header select {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-color);
}

.calendar-header button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.calendar-header select:hover,
.calendar-header button:hover {
    transform: translateY(-1px);
}

.calendar-header select:focus-visible,
.calendar-header button:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 2px;
}

/* 日历网格 */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: var(--bg-color);
    padding: 10px;
    transition: var(--transition-base);
    will-change: transform;
    transform: translateZ(0);
    contain: layout style;
}

/* 星期标题 */
.calendar-weekday {
    background-color: var(--bg-color);
    padding: 12px;
    text-align: center;
    font-weight: 600;
    color: var(--text-color);
    font-size: 14px;
}

/* 日期单元格 */
.calendar-day {
    background-color: white;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-base);
    border-radius: var(--border-radius);
    margin: 2px;
    position: relative;
    overflow: hidden;
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style paint;
}

.calendar-day:hover {
    background-color: #f0f0f0;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
    animation: pulse var(--animation-duration) ease-in-out;
    will-change: transform;
}

.calendar-day.today {
    border: 2px solid var(--primary-color);
    font-weight: bold;
}

.calendar-day.selected {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    font-weight: bold;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.2);
    animation: scaleIn var(--animation-duration) ease-out;
    will-change: transform, opacity;
}

.calendar-day.selected::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, 
        rgba(255,255,255,0) 0%, 
        rgba(255,255,255,0.2) 50%, 
        rgba(255,255,255,0) 100%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite;
    will-change: background-position;
    transform: translateZ(0);
}

.calendar-day.other-month {
    color: #ccc;
    background: #fafafa;
    transition: var(--transition-base);
}

.calendar-day.other-month:hover {
    transform: translateY(-2px) scale(1.05);
    background: #f0f0f0;
}

.calendar-day.weekend {
    color: var(--weekend-color);
}

.calendar-day:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 2px;
    z-index: 1;
}

/* ==========================================================================
   按钮组件
   ========================================================================== */
button {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 12px 25px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: var(--transition-base);
    margin: 20px 0;
    position: relative;
    overflow: hidden;
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style paint;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
    will-change: transform;
}

button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
    will-change: transform, opacity;
    transform: translateZ(0);
}

button:active::after {
    animation: ripple 0.6s ease-out;
}

button:focus-visible {
    outline: var(--focus-outline);
    outline-offset: 2px;
}

/* ==========================================================================
   结果区域
   ========================================================================== */
#result {
    margin: 25px 0;
    font-size: 1.3em;
    font-weight: 600;
    padding: 15px;
    border-radius: var(--border-radius);
    background: var(--bg-color);
    transition: var(--transition-base);
    animation: slideIn 0.5s ease-out;
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style;
}

#result.updating {
    opacity: 0.5;
    transform: translateY(-10px);
    will-change: transform, opacity;
}

/* 确保结果文本颜色对比度 */
#result[style*="color: #4CAF50"] {
    color: #2E7D32 !important; /* 更深的绿色，提高对比度 */
}

#result[style*="color: #FF5722"] {
    color: #D84315 !important; /* 更深的橙色，提高对比度 */
}

/* ==========================================================================
   关注列表
   ========================================================================== */
.focus-list {
    margin-top: 40px;
    background: white;
    padding: 20px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.8s ease-out;
    will-change: transform, opacity;
    transform: translateZ(0);
    contain: layout style;
}

.focus-list h3 {
    color: var(--text-color);
    font-size: 20px;
    margin-bottom: 20px;
    font-weight: 600;
}

.focus-list table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 15px;
}

.focus-list th,
.focus-list td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.focus-list th {
    background-color: var(--bg-color);
    font-weight: 600;
    color: var(--text-color);
}

.focus-list tr {
    animation: slideIn 0.5s ease-out;
    animation-fill-mode: both;
    transition: var(--transition-base);
    will-change: transform;
    transform: translateZ(0);
    contain: layout style;
}

.focus-list tr:nth-child(1) { animation-delay: 0.1s; }
.focus-list tr:nth-child(2) { animation-delay: 0.2s; }
.focus-list tr:nth-child(3) { animation-delay: 0.3s; }

.focus-list tr:hover {
    transform: translateX(5px);
    background-color: var(--bg-color);
    box-shadow: -2px 0 0 var(--primary-color);
    will-change: transform;
}

/* 表格行焦点状态 */
.focus-list tr:focus-visible {
    outline: var(--focus-outline);
    outline-offset: -2px;
}

/* 确保表格文本颜色对比度 */
.focus-list th {
    color: #1a1a1a; /* 更深的文本颜色 */
}

/* ==========================================================================
   加载动画
   ========================================================================== */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: loading 1s linear infinite;
    margin-left: 10px;
    will-change: transform;
    transform: translateZ(0);
    contain: layout style paint;
}

/* 为屏幕阅读器添加加载状态文本 */
.loading::before {
    content: "加载中";
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   动画关键帧
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateX(-20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes ripple {
    0% { transform: scale(0, 0); opacity: 0.5; }
    100% { transform: scale(20, 20); opacity: 0; }
}

@keyframes loading {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   主题控制
   ========================================================================== */
.theme-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    transition: transform 0.3s ease-in-out;
    transform: translateX(0);
}

.theme-controls.hidden {
    transform: translateX(calc(100% + 20px));
}

#themeToggle {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
}

#themeToggle:hover {
    transform: rotate(30deg);
}

.theme-icon {
    font-size: 20px;
}

.theme-colors {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-color-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background: var(--theme-color);
    cursor: pointer;
    transition: var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.theme-color-btn:hover {
    transform: scale(1.1);
}

/* 显示/隐藏触发器 */
.theme-controls::before {
    content: '🎨';
    position: absolute;
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.theme-controls::before:hover {
    transform: translateY(-50%) scale(1.1);
}

/* 深色模式样式 */
[data-theme="dark"] body {
    background: linear-gradient(135deg, var(--bg-color-darker) 0%, var(--bg-color-dark) 100%);
}

[data-theme="dark"] .container {
    background-color: rgba(26, 26, 26, 0.95);
    color: var(--text-color-light);
}

[data-theme="dark"] .calendar {
    background: var(--bg-color-dark);
}

[data-theme="dark"] .calendar-day {
    background-color: var(--bg-color);
    color: var(--text-color-light);
}

[data-theme="dark"] .calendar-day:hover {
    background-color: var(--bg-color-darker);
}

[data-theme="dark"] .calendar-day.other-month {
    color: #666;
    background: var(--bg-color-darker);
}

[data-theme="dark"] .focus-list {
    background: var(--bg-color);
}

[data-theme="dark"] .focus-list th {
    background-color: var(--bg-color-darker);
    color: var(--text-color-light);
}

[data-theme="dark"] .focus-list tr:hover {
    background-color: var(--bg-color-darker);
}

[data-theme="dark"] #result {
    background: var(--bg-color);
    color: var(--text-color-light);
}

/* ==========================================================================
   页面过渡动画
   ========================================================================== */
.page-transition {
    animation: pageEnter 0.5s ease-out;
}

@keyframes pageEnter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   触摸反馈效果
   ========================================================================== */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, #fff 10%, transparent 10.01%);
    background-repeat: no-repeat;
    background-position: 50%;
    transform: scale(10, 10);
    opacity: 0;
    transition: transform var(--ripple-duration), opacity var(--ripple-duration);
}

.ripple:active::after {
    transform: scale(0, 0);
    opacity: 0.3;
    transition: 0s;
}

/* ==========================================================================
   加载状态
   ========================================================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(4px);
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    position: absolute;
    bottom: 40%;
    font-size: 16px;
    color: var(--text-color);
    animation: pulse 1.5s ease-in-out infinite;
}

/* 深色模式下的加载状态 */
[data-theme="dark"] .loading-overlay {
    background: rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .loading-text {
    color: var(--text-color-light);
}

/* ==========================================================================
   日历组件动画
   ========================================================================== */
.calendar {
    animation: calendarEnter 0.5s ease-out;
}

@keyframes calendarEnter {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.calendar-day {
    transition: transform 0.2s, background-color 0.2s;
}

.calendar-day:active {
    transform: scale(0.95);
}

/* ==========================================================================
   结果区域动画
   ========================================================================== */
#result {
    animation: resultEnter 0.5s ease-out;
}

@keyframes resultEnter {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   关注列表动画
   ========================================================================== */
.focus-list {
    animation: listEnter 0.5s ease-out;
}

@keyframes listEnter {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.focus-list tr {
    animation: rowEnter 0.3s ease-out;
    animation-fill-mode: both;
}

@keyframes rowEnter {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==========================================================================
   按钮动画
   ========================================================================== */
button {
    transition: transform 0.2s, box-shadow 0.2s;
}

button:active {
    transform: scale(0.98);
}

/* ==========================================================================
   主题控制动画
   ========================================================================== */
.theme-controls {
    animation: controlsEnter 0.5s ease-out;
}

@keyframes controlsEnter {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.theme-controls.hidden {
    animation: controlsExit 0.3s ease-in forwards;
}

@keyframes controlsExit {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}